package com.food.foodapi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.food.foodapi.instans.Result;
import com.food.foodapi.mapper.UserMapper;
import com.food.foodapi.model.entity.User;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

/**
 * @author 92110
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @GetMapping("/info")
    public Result getUserInfo(HttpSession session) {
        String username = (String) session.getAttribute("username");
        User user = userMapper.selectOne(new QueryWrapper<User>().eq("username", username));
        return Result.success(user);
    }

    @PutMapping("/update")
    public Result updateUserInfo(@RequestBody User user) {
        userMapper.updateById(user);
        return Result.success();
    }
}
